package edu.mju.scenic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import edu.mju.scenic.entity.Img;
import edu.mju.scenic.mapper.ImgMapper;
import edu.mju.scenic.service.ImgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CBL
 * @since 2020-12-28
 */
@Service
public class ImgServiceImpl extends ServiceImpl<ImgMapper, Img> implements ImgService {

    @Override
    public boolean deleteBySpotId(Integer id) {
        return baseMapper.deleteBySpotId(id);
    }

    @Override
    public Map<String, Object> getImgInfo(IPage<Img> imgIPage) {
        QueryWrapper<Img> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",1);
        baseMapper.selectPage(imgIPage,queryWrapper);

        long total = imgIPage.getTotal();
        List<Img> list = imgIPage.getRecords();

        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("imgList",list);
        return map;
    }

    @Override
    public boolean deleteById(Long id) {
        int i = baseMapper.deleteByImgId(id);
        if(i>0){
            return true;
        }
        return false;
    }
}
